package au.com.bus4u.controller;

import au.com.bus4u.service.MenuService;
import au.com.bus4u.service.OrderService;
import au.com.bus4u.service.UserService;
import au.com.bus4u.utils.PageData;
import lombok.extern.java.Log;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/admin")
@Log
public class HtmlAdminController extends BaseController  {
    @Autowired
    private HttpServletRequest request;
    @Autowired
    private UserService userService;
    @Autowired
    private OrderService orderService;
    @Autowired
    private MenuService menuService;


    //跳转main页面
    @RequestMapping({"/main","/main.html"})
    public ModelAndView toAdminPage()throws Exception{
        log.info("=========================================");
//        System.err.println("HtmlAdminController.toAdminPage");
        ModelAndView mv = new ModelAndView();

        Map<String,Object> map = new HashMap<String,Object>();
        map.put("title","bus4u");//页面title
        map.put("active",-1);
        mv.addObject("data",map);

        Integer role_id = getCurrentUser().getInt("role_id");

        List<PageData> menuList = menuService.findByRoleIdAndMenuPId(role_id,0);
        for (int i = 0; i < menuList.size(); i++) {
//            System.out.println(i+"  = " +  menuList.get(i));
        }
        mv.addObject("menuList", menuList);
        mv.setViewName("/admin/main.html");
        return mv;
    }


    //跳转[菜单管理]页面
    @RequestMapping({"/menu/manage"})
    public ModelAndView toMenuList(@RequestParam(value = "menu_pid", required = false) Integer menu_pid)throws Exception{
        log.info("=========================================");
//        System.err.println("HtmlAdminController.toMenuPage");
        ModelAndView mv = new ModelAndView();
//        System.err.println("menu_pid = [" + menu_pid + "]");

        mv.addObject("title", "菜单管理");
        mv.addObject("menu_pid", menu_pid);

        mv.setViewName("/admin/menu/manage");
        return mv;
    }



    /**
     * 跳转到菜单管理
     *
     */
    @RequestMapping("/toMenuManager")
    public String toMenuManager() {
        log.info("=========================================");
        return "/admin/menu/menuManager";
    }
    //跳转游客订单
    @RequestMapping({"/toGuestOrderList"})
    public String toGuestOrderList()throws Exception{
        log.info("=========================================");
        return "/admin/order/guestOrderManage";
    }
    //跳转游客订单-旧数据
    @RequestMapping({"/toGuestOrderOldList"})
    public String toGuestOrderOldList()throws Exception{
        log.info("=========================================");
        return "/admin/order/guestOrderOldManage";
    }

    //班车订单 管理
    @RequestMapping({"/toShuttleBusOrderList"})
    public String toShuttleBusOrderList()throws Exception{
        log.info("=========================================");
        return "/admin/order/shuttleBusOrder";
    }

    //包车订单 管理
    @RequestMapping({"/toCharterBusOrderList"})
    public String toCharterBusOrderList()throws Exception{
        log.info("=========================================");
        return "/admin/order/charterBusOrder";
    }

    //跳转司机管理
    @RequestMapping({"/toDriverManager"})
    public String toDriverManager()throws Exception{
        log.info("=========================================");
        return "/admin/servicePersonal/driverManage";
    }
    //跳转承运商管理
    @RequestMapping({"/toCarrierManager"})
    public String toCarrierManager()throws Exception{
        log.info("=========================================");
        return "/admin/servicePersonal/carrierManage";
    }
    //跳转角色管理
    @RequestMapping({"/toRoleManager"})
    public String toRoleManager()throws Exception{
        log.info("=========================================");
        return "/admin/role/roleManager";
    }
    //跳转用户管理
    @RequestMapping({"/toUserManager"})
    public String toUserManager()throws Exception{
        log.info("=========================================");
        return "/admin/user/userManager";
    }




    /**
     * 跳转到菜单管理-left
     *
     */
    @RequestMapping("toMenuLeft")
    public String toMenuLeft() {
        log.info("=========================================");
        return "/admin/menu/menuLeft";
    }


    /**
     * 跳转到菜单管理--right
     *
     */
    @RequestMapping("toMenuRight")
    public String toMenuRight() {
        log.info("=========================================");
        return "/admin/menu/menuRight";
    }

    /**
     * 跳转到权限管理
     *
     */
    @RequestMapping("toPermissionManager")
    public String toPermissionManager() {
        log.info("=========================================");
        return "/admin/permission/permissionManager";
    }

    /**
     * 跳转到权限管理-left
     *
     */
    @RequestMapping("toPermissionLeft")
    public String toPermissionLeft() {
        log.info("=========================================");
        return "/admin/permission/permissionLeft";
    }


    /**
     * 跳转到权限管理--right
     *
     */
    @RequestMapping("toPermissionRight")
    public String toPermissionRight() {
        log.info("=========================================");
        return "/admin/permission/permissionRight";
    }


    /**
     * 跳转到缓存管理
     *
     */
    @RequestMapping("toCacheManager")
    public String toCacheManager() {
        log.info("=========================================");
        return "/admin/cache/cacheManager";
    }

}
